/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
/*
 * 
 *  ======== c5509_mmc.h ========
 *
 */

#ifndef __C5509_MMC_H
#define __C5509_MMC_H

#include <csl_mmc.h>
#include <que.h>
#include <media.h>

/* Version number definition */
#define C5509_MMC_VERSION_1  0xAB01

#ifdef __cplusplus
extern "C" {
#endif

/*  Sector Length  */
#define C5509_MMC_SECLEN      256

#define C5509_MMC_MEDIATYPE   (MEDIA_TYPEBASE | 0x0001)


/*  Device Driver Configuration Parameters */
typedef struct _C5509_MMC_DrvrParams
{
    Int mmcCardId;   /* RCA - set by the application */
    Int noChan;      /* maximum number of channels required */
    Int byteOrder;   /* BYTESWAP / BYTENORMAL */
    Int mmcDmaChR;   /* DMA channel number used for READ operations */
    Int mmcDmaChWR;  /* DMA channel number used for WRITE operations */
    Int *bufR;       /* Buffer for DMA read */
    Int *bufWR;      /* Buffer for DMA write */
    struct _C5509_MMC_ChanObj *pChan; /* Array of (noChan number of)
                                       * Channel Objects
                                       */
} C5509_MMC_DrvrParams;

/*  MMC Global Object  */
typedef struct _C5509_MMC_DevObj
{
    Int         mmcDevNum;           /* MMC Device Number */
    C5509_MMC_DrvrParams drvrParams; /* Driver configuration parameters */
    MdUns       blockLen;            /* Size of the block on the media */
    QUE_Obj     pendList;            /* Queue of pending jobs */
    IOM_Packet  *currPacket;         /* Current job */
    MMC_CardObj cslCards;            /* CSL MMC card object */
    MMC_Handle  cslMMC;              /* CSL MMC handle */
    MdUns       buf[C5509_MMC_SECLEN]; /* Sector buffer - for use by driver */
    Int         chOpenCount;         /* Number of logical channels opened
                                      * on this device
                                      */
} C5509_MMC_DevObj;

/*  MMC Channel Object  */
typedef struct _C5509_MMC_ChanObj
{
    Int     mode;         /* IOM_INPUT or IOM_OUTPUT or both */
    Int     error;        /* Indicates the ERROR condition of a Channel */  
    Bool    inUse;        /* Indicates whether the channel is free or not */
    IOM_TiomCallback callback; /* CallBack function to be used */
    Ptr     callbackArg;  /* CallBack arguments to be sent with the function */
    C5509_MMC_DevObj *pHandle; /* Pointer to the Global Object */
} C5509_MMC_ChanObj;


/*  Media Read Write Structure  */
typedef struct _C5509_MMC_RdWrObj
{
    MdUns *buf;         /* Application supplied buffer */
    LgUns sectorNumber; /*
                         * Sector number to be read/written
                         * Corresponds to MEDIA_RdWrObj::address
                         */ 
    LgUns offset;       /* 
                         * Specifies the offset from where data should
                         * be read/written, offset is in WORDs.
                         * Corresponds to MEDIA_RdWrObj::subAddress
                         */
    LgUns length;       /* Specifes the number of words to be read/written */ 
    C5509_MMC_ChanObj *pChan; /* 
                               *  Pointer to the channel for which request 
                               *  has been issued. 
                               */
    Int count;           /* Variable used internally by the driver */ 
    Int stateParameter;  /* Variable used internally by the driver */   
    Int atomicStatus;    /* Variable used internally by the driver */  
} C5509_MMC_RdWrObj;

/*  Bind Params  */
typedef struct _C5509_MMC_DevParams
{
    Int                  versionId;   /* Version number, set by the application */
    MMC_InitObj          devParams;   /* Initialization params for the MMC */
    C5509_MMC_DrvrParams drvrParams;  /* Config params for the MMC driver */
    Uns                  ier0Mask;    /* interrupt mask for IER 0 */
    Uns                  ier1Mask;    /* interrupt mask for IER 0 */
} C5509_MMC_DevParams;

/*  Init function  */
Void C5509_MMC_init();

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif
